import hljs from "highlight.js";
import "highlight.js/styles/atom-one-light.css";
import "./mdToHTML.css"

// 通常的默认值们
const md = require("markdown-it")("commonmark", {
  highlight: function (str: string, lang: string) {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return `<pre class="hljs"><div class="_code-header"><span>${lang}</span><span id="$_copy_code" class="copy-code">Copy Code</span></div><div style="padding:12px;font-size:16px"><code class="${lang}">${hljs.highlight(str, { language: lang }).value}</code></div></pre>`
      } catch (__) {}
    }
    return  `<pre class="hljs"><code>${md.utils.escapeHtml(str)}</code></pre>`
  },
});

export default md;
